#include "tracking.h"
#include <fstream>


time_t t_start, t_end, t_calc_overlap = 0;

// Used for testing and debugging
int main() {
	

	vector<vector<bbox>> bboxes;
	dres graph, result,result_nms;
	bboxes.reserve(8000);

	t_start = time(NULL);
	// read the bboxes from file
	int n;
	ifstream fin;
	//fin.open("C:/My Files/Works/Research/Tracking/cpp/VideoFrames_1400_900_detec_res.txt");
	fin.open("F:/workspace2/CodeConvert/VideoFrames_1400_900_detec_res.txt");
	while (fin >> n) {
		vector<bbox> frame;
		frame.reserve(n);
		double val[5];
		for (int i = 0; i < n; i++) {
			bbox newBbox;
			for (int j = 0; j < 5; j++)
				fin >> newBbox.val[j];
			frame.push_back(newBbox);
		}
		bboxes.push_back(frame);
	}
	fin.close();
	t_end = time(NULL);
	cout << "Elapsed time for input is " << t_end - t_start << " seconds." << endl;

	
	// build the graph
	t_start = time(NULL);
	graph = bboxes2dres(bboxes);
	graph = build_graph(graph);
	t_end = time(NULL);
	cout << "Elapsed time is " << t_end - t_start << " seconds." << endl;
	cout << "Elapsed time for calc_overlap is " << t_calc_overlap << "seconds." << endl;

	// Do tracking with nms
	t_start = time(NULL);
	//result = tracking_dp(graph, C_EN, C_EX, C_IJ, BETTA, THR_COST, MAX_IT, 0);
	result_nms = tracking_dp(graph, C_EN, C_EX, C_IJ, BETTA, THR_COST, MAX_IT, 1);
	t_end = time(NULL);
	cout << "Elapsed time is " << t_end - t_start << "seconds." << endl;
	
	system("pause");

	return 0;
}